package 开始的剑指offer8月.链表;
// https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/
public class 剑指Offer24反转链表0814 {

       class ListNode {
          int val;
          ListNode next;
          ListNode(int x) { val = x; }
      }

    class Solution {
        public ListNode reverseList(ListNode head) {
            //迭代
            // ListNode next,prev=null;
            // ListNode current=head;
            // while(current!=null){
            //     next=current.next;
            //     current.next=prev;
            //     prev=current;
            //     current=next;
            // }
            // return prev;

            //递归
            if(head==null||head.next==null)
            {
                return head;
            }
            ListNode p=reverseList(head.next);
            head.next.next=head;
            head.next=null;
            return p;
        }
    }

}
